﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using My.Data.DataAccess;
using My.Data.Factories;
using My.Data.BusinessObject;
using NHibernate.Criterion;
using System.Collections;

namespace NHibernate.App
{
    public partial class LoginForm : Form
    {
        private ILoginDao loginDao = DataAccessFactory.LoadLoginDao();
        private ITL1Dao TL1Dao = DataAccessFactory.LoadTL1Dao();
        private static string userType_;
        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IList<Login> loginList = loginDao.GetAll();
            ICriteria query = loginDao.ISession.CreateCriteria(typeof(Login))
                                     .Add(Restrictions.Eq("UserName", UserNameBox.Text))
                                     .Add(Restrictions.Eq("PassWord", PassWordBox.Text));
            IList<Login> personId = query.List<Login>();

            userType_ = LoginChecker.check(personId[0], loginList);


            IList<Login> results = loginDao.ISession.CreateCriteria(typeof(Login))
            .Add(Expression.Eq("UserName", UserNameBox.Text))
            .Add(Expression.Eq("PassWord", PassWordBox.Text))
            .List<Login>();

            Factory forms = new Factory(results[0].Id);
            forms.createForm(userType_);
        }

        private void RegisterBtn_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();
            registerForm.ShowDialog();
        }
    }
}
